<?php

namespace App\Models\Strator;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Models\Traits\DateTimeTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Traits\ModelSearchTrait;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class Strator extends Authenticatable
{
    use SoftDeletes, DateTimeTrait, ModelSearchTrait;

    //
    protected $guarded = ['strator_password','is_suspended','is_super'];
    protected $hidden=['strator_password','deleted_at'];
    //
    protected $dateFormat = 'Y-m-d H:i:s';

    //
    public function searchConditions():array{
        return [
            ['strator_account','like'],
            ['strator_email','='],
            ['strator_mobile','='],
            ['strator_nickname','like'],
            ['is_suspended','='],
        ];
    }
    public function department(){
        return $this->belongsTo(StratorDepartment::class,'department_id','id');
    }
    //
    public function tokens():HasMany{
        return $this->hasMany(StratorAuthToken::class,'strator_id','id');
    }
    //
    public function permissions():BelongsToMany{
        return $this->belongsToMany(StratorPermission::class,'strator_has_permissions','strator_id','permission_id','id','id')->wherePivotNull('deleted_at');
    }
    //
    public function positions():BelongsToMany{
        return $this->belongsToMany(StratorPosition::class,'strator_has_positions','strator_id','position_id','id','id')->wherePivotNull('deleted_at');
    }


}
